home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
- __cvsid__ = '$Id: introspect.py 39896 2006-06-29 22:24:00Z RD $'
- __revision__ = '$Revision: 39896 $'[11:-2]
- import cStringIO
- import inspect
- import sys
- import tokenize
- import types
- import wx
-
- def getAutoCompleteList(command = '', locals = None, includeMagic = 1, includeSingle = 1, includeDouble = 1):
- attributes = []
- root = getRoot(command, terminator = '.')
-
- try:
- if locals is not None:
- object = eval(root, locals)
- else:
- object = eval(root)
- except:
- pass
-
- attributes = getAttributeNames(object, includeMagic, includeSingle, includeDouble)
- return attributes
-
-
- def getAttributeNames(object, includeMagic = 1, includeSingle = 1, includeDouble = 1):
- attributes = []
- dict = { }
- str_type = str(type(object))
- for item in attributes:
- dict[item] = None
-
- attributes = dict.keys()
- attributes = _[3]
- attributes.sort((lambda x, y: cmp(x.upper(), y.upper())))
- if not includeDouble:
- attributes = filter((lambda item: item[:2] != '__'), attributes)
-
- return attributes
-
-
- def hasattrAlwaysReturnsTrue(object):
- return hasattr(object, 'bogu5_123_aTTri8ute')
-
-
- def getAllAttributeNames(object):
- attrdict = { }
-
- try:
- key = type(object).__name__
- except:
- key = 'anonymous'
-
- wakeupcall = dir(object)
- del wakeupcall
- attributes = dir(object)
- attrdict[(key, 'dir', len(attributes))] = attributes
-
- try:
- attributes = object.__dict__.keys()
- attributes.sort()
- except:
- pass
-
- attrdict[(key, '__dict__', len(attributes))] = attributes
-
- try:
- klass = object.__class__
- except:
- pass
-
- if klass is object:
- pass
- else:
- attrdict.update(getAllAttributeNames(klass))
-
- try:
- bases = object.__bases__
- except:
- pass
-
- if isinstance(bases, types.TupleType):
- for base in bases:
- if type(base) is types.TypeType:
- continue
- attrdict.update(getAllAttributeNames(base))
-
-
- return attrdict
-
-
- def getCallTip(command = '', locals = None):
- calltip = ('', '', '')
- root = getRoot(command, terminator = '(')
-
- try:
- if locals is not None:
- object = eval(root, locals)
- else:
- object = eval(root)
- except:
- return calltip
-
- name = ''
- (object, dropSelf) = getBaseObject(object)
-
- try:
- name = object.__name__
- except AttributeError:
- pass
-
- tip1 = ''
- argspec = ''
- if inspect.isbuiltin(object):
- pass
- elif inspect.isfunction(object):
- argspec = apply(inspect.formatargspec, inspect.getargspec(object))
- if dropSelf:
- temp = argspec.split(',')
- if len(temp) == 1:
- argspec = '()'
- elif temp[0][:2] == '(*':
- pass
- else:
- argspec = '(' + ','.join(temp[1:]).lstrip()
-
- tip1 = name + argspec
-
- doc = ''
- if callable(object):
-
- try:
- doc = inspect.getdoc(object)
-
-
- if doc:
- firstline = doc.split('\n')[0].lstrip()
- if tip1 == firstline or firstline[:len(name) + 1] == name + '(':
- tip1 = ''
- else:
- tip1 += '\n\n'
- docpieces = doc.split('\n\n')
- tip2 = docpieces[0]
- tip3 = '\n\n'.join(docpieces[1:])
- tip = '%s%s\n\n%s' % (tip1, tip2, tip3)
- else:
- tip = tip1
- calltip = (name, argspec[1:-1], tip.strip())
- return calltip
-
-
- def getRoot(command, terminator = None):
- command = command.split('\n')[-1]
- if command.startswith(sys.ps2):
- command = command[len(sys.ps2):]
-
- command = command.lstrip()
- command = rtrimTerminus(command, terminator)
- tokens = getTokens(command)
- if not tokens:
- return ''
-
- if tokens[-1][0] is tokenize.ENDMARKER:
- del tokens[-1]
-
- if not tokens:
- return ''
-
- if terminator == '.':
- if tokens[-1][1] != '.' or tokens[-1][0] is not tokenize.OP:
- return ''
- elif terminator and command.endswith(terminator):
- size = 0 - len(terminator)
- command = command[:size]
-
- command = command.rstrip()
- tokens = getTokens(command)
- tokens.reverse()
- line = ''
- start = None
- prefix = ''
- laststring = '.'
- emptyTypes = ('[]', '()', '{}')
- for token in tokens:
- tokentype = token[0]
- tokenstring = token[1]
- line = token[4]
- if tokentype is tokenize.ENDMARKER:
- continue
-
- if tokentype in (tokenize.NAME, tokenize.STRING, tokenize.NUMBER) and laststring != '.':
- if prefix and line[token[3][1]] != ' ':
- prefix = ''
-
- break
-
- if (tokentype in (tokenize.NAME, tokenize.STRING, tokenize.NUMBER) or tokentype is tokenize.OP) and tokenstring == '.':
- if prefix:
- prefix = ''
- break
- else:
- start = token[2][1]
- elif len(tokenstring) == 1 and tokenstring in '[({])}':
- if prefix in emptyTypes and tokenstring in '[({':
- break
- else:
- prefix = tokenstring + prefix
- else:
- break
- laststring = tokenstring
-
- if start is None:
- start = len(line)
-
- root = line[start:]
- if prefix in emptyTypes:
- root = prefix + root
-
- return root
-
-
- def getTokens(command):
- if type(command) == unicode:
-
- try:
- command = command.encode(wx.GetDefaultPyEncoding())
- except UnicodeEncodeError:
- pass
- except:
- None<EXCEPTION MATCH>UnicodeEncodeError
-
-
- None<EXCEPTION MATCH>UnicodeEncodeError
- f = cStringIO.StringIO(command)
- tokens = []
-
- try:
-
- def eater(*args):
- tokens.append(args)
-
- tokenize.tokenize_loop(f.readline, eater)
- except tokenize.TokenError:
- pass
-
- return tokens
-
-
- def rtrimTerminus(command, terminator = None):
- if terminator:
- pieces = command.split(terminator)
- if len(pieces) > 1:
- command = terminator.join(pieces[:-1]) + terminator
-
-
- return command
-
-
- def getBaseObject(object):
- if inspect.isbuiltin(object):
- dropSelf = 0
- elif inspect.ismethod(object):
-
- try:
- if object.im_self is None:
- dropSelf = 0
- else:
- dropSelf = 1
- object = object.im_func
- except AttributeError:
- dropSelf = 0
- except:
- None<EXCEPTION MATCH>AttributeError
-
-
- None<EXCEPTION MATCH>AttributeError
- if inspect.isclass(object):
- constructor = getConstructor(object)
- if constructor is not None:
- object = constructor
- dropSelf = 1
- else:
- dropSelf = 0
- elif callable(object):
-
- try:
- object = object.__call__.im_func
- dropSelf = 1
- except AttributeError:
- dropSelf = 0
- except:
- None<EXCEPTION MATCH>AttributeError
-
-
- None<EXCEPTION MATCH>AttributeError
- dropSelf = 0
- return (object, dropSelf)
-
-
- def getConstructor(object):
-
- try:
- return object.__init__.im_func
- except AttributeError:
- for base in object.__bases__:
- constructor = getConstructor(base)
- if constructor is not None:
- return constructor
- continue
-
-
-
-